import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/ps/psPlanningScheduling/list',
  save = '/ps/psPlanningScheduling/add',
  edit = '/ps/psPlanningScheduling/edit',
  deleteOne = '/ps/psPlanningScheduling/delete',
  deleteBatch = '/ps/psPlanningScheduling/deleteBatch',
  importExcel = '/ps/psPlanningScheduling/importStation',
  distribute = '/ps/psPlanningScheduling/distribute',
  exportXls = '/ps/psPlanningScheduling/exportXls',
  psPlanningSchedulingOrderContentList = '/ps/psPlanningScheduling/queryPsPlanningSchedulingOrderContentByMainId',
  psPlanningSchedulingAvailableResourcesList = '/ps/psPlanningScheduling/queryPsPlanningSchedulingAvailableResourcesByMainId',
  psPlanningSchedulingProcessDetailList = '/ps/psPlanningScheduling/queryPsPlanningSchedulingProcessDetailByMainId',
  queryMpsItemByMainIds = '/psProductionPlanMps/queryItemByMainIds',
  queryArrangementItemByMainIds = '/ps/psProductionArrangementPlans/queryItemByMainIds',
  queryPsProductionArrangementPlansItemByMainId = '/ps/psProductionArrangementPlans/queryPsProductionArrangementPlansItemByMainId',
  calculate = '/ps/psPlanningScheduling/calculate',
  psProductionArrangementImitatePlansAll = '/ps/psProductionArrangementImitatePlans/all',
  schedulingList = '/ps/psPlanningScheduling/scheduling/list',
  gerPRAlarmList = '/ps/psPlanningScheduling/scheduling/getPRAlarmList',
  schedulingAdd = "/ps/psPlanningScheduling/add",
  schedulingEdit = "/ps/psPlanningScheduling/edit",
  schedulingDel = "/ps/psPlanningScheduling/delete",
  gerProductionSchedulingLogList = '/ps/psProductionArrangementPlansResult/list',
  psPlanningSchedulingOrderContentDelete = '/ps/psPlanningScheduling/deleteContent',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
// 根据生产主计划id集合批量查询明细
export const getMpsItemByMainIds = (params) =>
  defHttp.get({ url: Api.queryMpsItemByMainIds, params });
// 根据总装排查计划id集合批量查询明细
export const getArrangementItemByMainIds = (params) =>
  defHttp.get({ url: Api.queryArrangementItemByMainIds, params });
// 排产作业
export const calculate = (params) =>
  defHttp.post({ url: Api.calculate, params });
//模拟排产-全部列表
export const getPsProductionArrangementImitatePlansAll = (params) =>
  defHttp.get({ url: Api.psProductionArrangementImitatePlansAll + `/${params.id}` });
// 排产工作台详情-查询
export const schedulingList = (params) =>
  defHttp.post({ url: Api.schedulingList, params }, { joinParamsToUrl: true });
export const gerPRAlarmList = (params) =>
  defHttp.post({ url: Api.gerPRAlarmList, params }, { joinParamsToUrl: true });
// 排产日志
export const gerProductionSchedulingLogList = (params) =>
  defHttp.get({ url: Api.gerProductionSchedulingLogList, params }, { joinParamsToUrl: true });
// 排产工作详情-添加
// export const schedulingAdd = (params) =>
//   defHttp.post({url: Api.schedulingAdd, params});
// 排产工作详情-删除
export const schedulingDel = (params) =>
  defHttp.post({ url: Api.schedulingDel, params });
// 排产工作详情-编辑
// export const schedulingEdit = (params) =>
//   defHttp.post({url: Api.schedulingEdit, params});

/**
 * 计划下发
 */
export const distributePlan = (params) =>
  defHttp.post({ url: Api.distribute, params });
/**
 * 查询子表数据
 * @param params
 */
export const psPlanningSchedulingOrderContentList = Api.psPlanningSchedulingOrderContentList;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanningSchedulingAvailableResourcesList = Api.psPlanningSchedulingAvailableResourcesList;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanningSchedulingProcessDetailList = Api.psPlanningSchedulingProcessDetailList;

/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
export const psPlanningSchedulingOrderContentDelete = (id, handleSuccess)=>{
  return defHttp.delete({ url: Api.psPlanningSchedulingOrderContentDelete, params:{id} }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (data, isUpdate) => {
  let url =  isUpdate ? Api.schedulingEdit : Api.schedulingAdd;
  return defHttp.post({ url: url, data });
}
